package com.service.common;

import com.dao.common.UserMapper;
import com.entity.common.ApiResult;
import com.entity.common.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/2.
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> getPageList(User record){
        return userMapper.getPageList(record);
    }

    public ApiResult addUser(User user) {
        int num = userMapper.insertSelective(user);
        return  new ApiResult(num);
    }

    public ApiResult getUserById(Integer id) {
        User user = userMapper.selectByPrimaryKey(id);
        return new ApiResult(true,"获取数据成功！",user);
    }

    public ApiResult editUser(User user) {
        int num = userMapper.updateByPrimaryKeySelective(user);
        return  new ApiResult(num);
    }

    public ApiResult deleteUser(int id) {
        int num = userMapper.deleteByPrimaryKey(id);
        return  new ApiResult(num);
    }

    public ApiResult editUserByUserName(User user) {
        int num=userMapper.editUserByUserName(user);
        return  new ApiResult(num);
    }
}
